package com.tedu.parkinglot.equipment.service.impl;

import com.tedu.parkinglot.equipment.mapper.EquipmentMapper;
import com.tedu.parkinglot.equipment.pojo.dto.EquipmentQuery;
import com.tedu.parkinglot.equipment.pojo.dto.EquipmentSaveParam;
import com.tedu.parkinglot.equipment.pojo.entity.Equipment;
import com.tedu.parkinglot.equipment.pojo.vo.EquipmentVO;
import com.tedu.parkinglot.equipment.service.EquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class EquipmentServiceImpl implements EquipmentService {
    @Autowired
    EquipmentMapper equipmentMapper;

    @Override
    public List<EquipmentVO> selectEquipment(EquipmentQuery equipmentQuery) {
        log.debug("查询设备业务：equipmentQuery",equipmentQuery);
        List<EquipmentVO> list=equipmentMapper.selectEquipment(equipmentQuery);
        log.debug("结果为:list={}",list);
        return list;
    }

    @Override
    public void saveEquipment(EquipmentSaveParam equipmentSaveParam) {
        log.debug("保存设备业务：equipmentSaveParam",equipmentSaveParam);
        Equipment equipment= new Equipment();
        BeanUtils.copyProperties(equipmentSaveParam,equipment);
        if (equipment.getId()==null){
            equipment.setCreate_time(new Date());
            log.debug(String.valueOf(equipment.getCreate_time()));
            equipmentMapper.insert(equipment);
        }else {
            equipment.setUpdate_time(new Date());
            equipmentMapper.update(equipment);
        }
    }

    @Override
    public void deleteEquipment(Long id) {
        log.debug("删除设备：id",id);
        equipmentMapper.delete(id);
    }

    @Override
    public void updateStatus(Long id, String status) {
        log.debug("更新状态业务：id={},status={}",id,status);
        Equipment equipment=new Equipment();
        equipment.setId(id);
        equipment.setStatus(status);
        equipment.setUpdate_time(new Date());
        equipmentMapper.update(equipment);
    }
}
